<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2_回调形式refs</title>
</head>
<body>
<div id="test"></div>

<script type="text/javascript" src="../js/react.development.js"></script>
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<script type="text/javascript" src="../js/babel.min.js"></script>

<script type="text/babel">

    class Demo extends React.Component {
        //createRef()调用后可以返回一个容器，该容器可以存储被ref所标识的节点
        //该容器专人专用的
        myRef = React.createRef()
        showData = () => {
            console.log(this.myRef.current.value)
        }
        showData2 = () => {
            const {input2} = this
            alert(input2.value)
        }

        render() {
            return (
                <div>
                    <input ref={this.myRef} type="text" placeholder="点击按钮提示数据"/>&nbsp;
                    <button onClick={this.showData}>点击我提示左边数据</button>
                    &nbsp;
                </div>
            )
        }
    }

    ReactDOM.render(<Demo/>, document.getElementById('test'))
</script>
</body>
</html>
